package com.lingchen.boot.thread;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * Created by lc on 2018/12/13
 */
public class NIOClient {
    public static void main(String[] args) throws IOException {
        SocketChannel channel = SocketChannel.open();
        channel.configureBlocking(false);

        InetSocketAddress address = new InetSocketAddress("127.0.0.1", 9999);
        if (!channel.connect(address)) {
            while (!channel.finishConnect()) {
                System.out.println("Client:连接服务器......");
            }
        }

        String msg = "hello,Server";
        ByteBuffer writeBuf = ByteBuffer.wrap(msg.getBytes());
        channel.write(writeBuf);

        System.in.read();
    }
}
